﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;

/// <summary>
/// 出牌回合
/// </summary>
public class RoundModel
{
    /// <summary>
    /// 玩家出牌事件
    /// </summary>
    public static event Action<bool> PlayerHandler;
    /// <summary>
    /// 电脑出牌事件
    /// </summary>
    public static event Action<ComputerSmartAgrs> ComputerHandler;

    private CharacterType biggestCharacter;
    private CharacterType currentCharacter;
    private CardType currentCardType;
    private int currentWeight;
    private int currentLength;

    /// <summary>
    /// 最大出牌者
    /// </summary>
    public CharacterType BiggestCharacter
    {
        get
        {
            return biggestCharacter;
        }

        set
        {
            biggestCharacter = value;
        }
    }

    /// <summary>
    /// 当前出牌者
    /// </summary>
    public CharacterType CurrentCharacter
    {
        get
        {
            return currentCharacter;
        }

        set
        {
            currentCharacter = value;
        }
    }

    /// <summary>
    /// 当前的牌型
    /// </summary>
    public CardType CurrentCardType
    {
        get
        {
            return currentCardType;
        }

        set
        {
            currentCardType = value;
        }
    }

    /// <summary>
    /// 当前出牌的大小
    /// </summary>
    public int CurrentWeight
    {
        get
        {
            return currentWeight;
        }

        set
        {
            currentWeight = value;
        }
    }

    /// <summary>
    /// 当前出牌的长度
    /// </summary>
    public int CurrentLength
    {
        get
        {
            return currentLength;
        }

        set
        {
            currentLength = value;
        }
    }
    /// <summary>
    /// 初始化回合
    /// </summary>
    public void InitRound()
    {
        this.biggestCharacter = CharacterType.Desk;
        this.currentCharacter = CharacterType.Desk;
        this.currentCardType = CardType.None;
        this.currentLength = 0;
        this.currentWeight = 0;
    }
    /// <summary>
    /// 开始游戏
    /// </summary>
    /// <param name="cType"></param>
    public void Start(CharacterType cType)
    {
        this.BiggestCharacter = cType;
        this.CurrentCharacter = cType;
        BeginWith(cType);
    }

    /// <summary>
    /// 转换出牌
    /// 没转换一次 就调用一次
    /// </summary>
    public void Turn()
    {
        currentCharacter++;

        if (currentCharacter == CharacterType.Desk || currentCharacter == CharacterType.Library)
        {
            currentCharacter = CharacterType.Player;
        }
        BeginWith(currentCharacter);
    }

    /// <summary>
    /// 出牌
    /// </summary>
    /// <param name="cType"></param>
    private void BeginWith(CharacterType cType)
    {
        if (cType == CharacterType.Player)
        {
            if (PlayerHandler != null)
            {
                PlayerHandler(BiggestCharacter!= CharacterType.Player);
            }
        }
        else
        {
            if (ComputerHandler != null)
            {
                //CharacterType 出牌者,CardType出牌类型,int权重,int长度
                ComputerSmartAgrs ee = new ComputerSmartAgrs()
                {
                    character = this.CurrentCharacter,
                    cardType = this.CurrentCardType,
                    weight = this.CurrentWeight,
                    length = this.CurrentLength,
                    biggestCharacter = this.BiggestCharacter
                };
                ComputerHandler(ee);
            }
        }
    }
}
